Unit 4- PYQ
Q1. what is the Yule-Walker eqn and how are they used in the context of AR processes?
Great question! Let's break down the Yule-Walker Equations and how they are used in AR (AutoRegressive) processes in the simplest way possible.
🔁 What is an AR Process?
An AR(p) process is a type of time series model where:
Xt=ϕ1Xt−1+ϕ2Xt−2+⋯+ϕpXt−p+εtX_t = \phi_1 X_{t-1} + \phi_2 X_{t-2} + \dots + \phi_p X_{t-p} + \varepsilon_t
-
XtX_t: current value
-
ϕ1,…,ϕp\phi_1, \dots, \phi_p: AR coefficients
-
εt\varepsilon_t: white noise (random shock)
📐 What are Yule-Walker Equations?
Yule-Walker Equations help you calculate the AR coefficients (ϕ1,…,ϕp\phi_1, \dots, \phi_p) using autocorrelation values from your time series.
They are based on:
γ(k)=Cov(Xt,Xt−k)\gamma(k) = \text{Cov}(X_t, X_{t-k})
where γ(k)\gamma(k) is the autocovariance at lag kk.
🔧 Basic Form (for AR(1)):
For an AR(1) process:
Xt=ϕ1Xt−1+εtX_t = \phi_1 X_{t-1} + \varepsilon_t
The Yule-Walker equation becomes:
γ(1)=ϕ1γ(0)⇒ϕ1=γ(1)γ(0)=ρ(1)\gamma(1) = \phi_1 \gamma(0) \Rightarrow \phi_1 = \frac{\gamma(1)}{\gamma(0)} = \rho(1)
So the AR(1) coefficient is just the lag-1 autocorrelation!
🔢 General Form (for AR(p)):
You get a system of p equations:
γ(1)=ϕ1γ(0)+ϕ2γ(1)+⋯+ϕpγ(p−1)γ(2)=ϕ1γ(1)+ϕ2γ(0)+⋯+ϕpγ(p−2)⋮γ(p)=ϕ1γ(p−1)+⋯+ϕpγ(0)\gamma(1) = \phi_1 \gamma(0) + \phi_2 \gamma(1) + \dots + \phi_p \gamma(p-1) \ \gamma(2) = \phi_1 \gamma(1) + \phi_2 \gamma(0) + \dots + \phi_p \gamma(p-2) \ \vdots \ \gamma(p) = \phi_1 \gamma(p-1) + \dots + \phi_p \gamma(0)
You solve this system to find ϕ1,…,ϕp\phi_1, \dots, \phi_p.
💡 Why Are They Useful?
-
Instead of guessing AR coefficients, we can estimate them from data using sample autocorrelations.
-
This makes model fitting easier, especially for ARMA or ARIMA models in forecasting.
✅ Summary (Super Simple):
-
Yule-Walker equations connect autocorrelation values with AR coefficients.
-
They are used to estimate the parameters of an AR(p) model from time series data.
-
Think of them as a tool that says:
"Here's the autocorrelation at different lags. What AR model best explains this pattern?"
Would you like a numerical example too (like for AR(2))?
Q2. describe a scenario where deseasonlization would be crucial for accurate forecasting and analysis. How would you implement it?
Scenario Where Deseasonalization is Crucial:
Scenario:
A retail company sells air conditioners (ACs). Sales peak during summer (April to June) and drop in winter (December to February). You want to forecast future monthly sales to manage inventory and staff.
If you use raw sales data for forecasting, the model may:
-
Overestimate sales in winter (thinking a downward trend is starting)
-
Underestimate sales in summer (thinking it’s just a random spike)
🎯 Why Deseasonalization is Crucial:
To remove the seasonal effect, so you can:
-
Understand the true underlying trend (upward or downward sales)
-
Make better forecasts for business decisions (inventory, marketing)
⚙️ How to Implement Deseasonalization (Step-by-Step):
Let’s assume monthly data with seasonality of 12 months.
Step 1: Calculate Seasonal Indices
Use a multiplicative model:
Observed=Trend×Seasonal×Irregular\text{Observed} = \text{Trend} \times \text{Seasonal} \times \text
Or additive model:
Observed=Trend+Seasonal+Irregular\text{Observed} = \text{Trend} + \text{Seasonal} + \text
To get seasonal indices:
-
Compute a centered moving average (e.g., 12-month for monthly data) to estimate trend.
-
Subtract (additive) or divide (multiplicative) actual values by the trend to isolate seasonality.
-
Average the seasonal values by month (Jan, Feb, ..., Dec).
Step 2: Deseasonalize the Data
-
Additive Model:
Deseasonalized Data=Actual−Seasonal Index\text{Deseasonalized Data} = \text{Actual} - \text
-
Multiplicative Model:
Deseasonalized Data=ActualSeasonal Index\text{Deseasonalized Data} = \frac{\text{Actual}}{\text{Seasonal Index}}
Step 3: Model the Deseasonalized Series
-
Fit a trend model (e.g., linear regression or ARIMA) to the deseasonalized data.
-
Forecast future deseasonalized values.
Step 4: Reseasonalize the Forecast
-
Multiply (or add) the forecasted deseasonalized value by the seasonal index for that month:
Final Forecast=Deseasonalized Forecast×Seasonal Index\text{Final Forecast} = \text{Deseasonalized Forecast} \times \text
📝 Example (Multiplicative):
Let’s say April sales = ₹1,20,000
April seasonal index = 1.5 (means sales are 50% higher than average due to summer)
Deseasonalized value = ₹1,20,000 ÷ 1.5 = ₹80,000
→ This ₹80,000 is the real performance without seasonal influence.
✅ Final Thoughts:
Deseasonalization is crucial when:
-
Seasonality distorts the actual performance
-
You need clear trend/forecasting models
-
Business planning (e.g., budget, manpower, supply chain) relies on unbiased trends
Q3.
Great! Deseasonalization using harmonic analysis is a powerful technique based on Fourier series—a method that models seasonality as a sum of sine and cosine waves.
🌊 What is Harmonic Analysis?
Harmonic analysis models seasonal patterns using sine and cosine functions, like:
S(t)=a0+∑k=1K(akcos(2πktT)+bksin(2πktT))S(t) = a_0 + \sum_{k=1}^{K} \left( a_k \cos\left(\frac{2\pi kt}{T}\right) + b_k \sin\left(\frac{2\pi kt}{T}\right) \right)
Where:
-
S(t)S(t) is the seasonal component at time tt
-
TT is the period (e.g. 12 for monthly seasonality)
-
KK is the number of harmonics (e.g., 1, 2, or 3)
-
ak,bka_k, b_k are the harmonic coefficients
🧠 Goal:
Estimate the seasonal component S(t)S(t), then remove it from the original series to get the deseasonalized data.
✅ Steps for Deseasonalization Using Harmonic Analysis:
Step 1: Prepare the Time Series
-
Ensure your data is evenly spaced (e.g., monthly, daily).
-
Remove any missing values.
-
Let’s call the time series Y(t)Y(t), with t=1,2,...,Nt = 1, 2, ..., N.
Step 2: Choose the Period (T)
-
Determine the seasonal period, e.g.:
-
Monthly data with yearly seasonality → T=12T = 12
-
Quarterly → T=4T = 4
-
Daily with weekly seasonality → T=7T = 7
-
Step 3: Fit Harmonic Regression Model
Build a regression model of the form:
Y(t)=α+∑k=1K(akcos(2πktT)+bksin(2πktT))+Residual(t)Y(t) = \alpha + \sum_{k=1}^{K} \left( a_k \cos\left(\frac{2\pi kt}{T}\right) + b_k \sin\left(\frac{2\pi kt}{T}\right) \right) + \text{Residual}(t)
-
α\alpha: intercept (mean level)
-
Choose K, the number of harmonics (typically 1 to 3 is enough for seasonal patterns)
-
Estimate ak,bka_k, b_k using least squares regression
Step 4: Estimate Seasonal Component
Use the fitted coefficients to compute:
S^(t)=α^+∑k=1K(a^kcos(2πktT)+b^ksin(2πktT))\hat{S}(t) = \hat{\alpha} + \sum_{k=1}^{K} \left( \hat{a}_k \cos\left(\frac{2\pi kt}{T}\right) + \hat{b}_k \sin\left(\frac{2\pi kt}{T}\right) \right)
This gives you the estimated seasonal effect at each time point.
Step 5: Deseasonalize the Series
Subtract the seasonal component from the original data:
Deseasonalized(t)=Y(t)−S^(t)\text{Deseasonalized}(t) = Y(t) - \hat{S}(t)
Now you're left with the trend + irregular components (useful for forecasting).
Step 6 (Optional): Forecasting and Reseasonalizing
-
Forecast the deseasonalized series using a trend model (e.g., linear, ARIMA).
-
Add back the seasonal component S^(t)\hat{S}(t) to get the final forecast:
Forecast(t)=Forecast of deseasonalized series+S^(t)\text{Forecast}(t) = \text{Forecast of deseasonalized series} + \hat{S}(t)
🧪 Example in One Line (Conceptual):
Imagine you're modeling monthly ice cream sales:
Fit a regression with terms like:
Sales ~ cos(2πt/12) + sin(2πt/12) + cos(4πt/12) + sin(4πt/12)
→ Use it to estimate seasonality → Subtract it → You get deseasonalized sales.
✅ Advantages of Harmonic Analysis:
-
Captures smooth cyclic patterns
-
Works well for multiple seasonal peaks
-
Less sensitive to noise than fixed seasonal indices
Would you like me to show this in Python or Excel with sample data?